package com.zysdev.ffmpegdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Environment
import android.view.View
import android.widget.TextView
import com.zysdev.ffmpegdemo.databinding.ActivityMainBinding
import com.zysdev.ffmpegdemo.utils.FFmpegUtil

class MainActivity : AppCompatActivity(), View.OnClickListener {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.buttonCodec.setOnClickListener(this)
        binding.buttonFilter.setOnClickListener(this)
        binding.buttonFormat.setOnClickListener(this)
        binding.buttonPlay.setOnClickListener(this)
        binding.buttonProtocol.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v) {
            binding.buttonProtocol -> {
                setInfoText(FFmpegUtil.urlProtocolInfo());
            }
            binding.buttonCodec -> {
                setInfoText(FFmpegUtil.avCodecInfo());
            }
            binding.buttonFilter -> {
                setInfoText(FFmpegUtil.avFilterInfo());
            }
            binding.buttonFormat -> {
                setInfoText(FFmpegUtil.avFormatInfo());
            }

            binding.buttonPlay -> {
//                val videoPath =
//                    getExternalFilesDir().absolutePath + "/Movies/Peru.mp4"
                val videoPath ="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
                binding.videoView.playVideo(videoPath)
            }
        }
    }

    private fun setInfoText(content: String) {
        binding.sampleText.text = content
    }

}